Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change net to operator #2846

Merged
merged 22 commits into from
Jul 16, 2017
Merged

change net to operator #2846

merged 22 commits into from
Jul 16, 2017

Conversation

jacquesqiao
Copy link
Member

@jacquesqiao jacquesqiao commented Jul 13, 2017

fix: #2857
review: #2851 first

* @brief Add an Operator according to `def`.
*/
virtual OpIndex AddOp(const OpProto &def) = 0;
virtual void AddOp(const OpDesc& def) = 0;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is better to make OpCreator returns a std::shared_ptr<OpBase>, and we could alias it to OpPtr.

AddOp should take a OpPtr.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


/**
* @brief Add optimizer operators acctording to `attrs`.
*/
virtual void AddOptimizerOps(const OpAttrs &attrs) = 0;
virtual void AddOptimizerOps() = 0;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AddOperatorOps and AddBackwardOps is not a member function of Network.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed


private:
// the operators owned by `Network`.
std::vector<Operator> ops_;
std::vector<std::unique_ptr<OperatorBase>> ops_;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

std::shared_ptr is better.

The std::shared_ptr is the only pointer can expose to Python correctly.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

PlainNet::PlainNet(const NetDesc& def) {}
void PlainNet::AddOp(const OpDesc& desc) {
std::unique_ptr<OperatorBase> op(OpRegistry::CreateOp(desc));
ops_.push_back(std::move(op));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

emplace_back is better.
emplace_back vs push_back

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, I will take a look~~

OpIndex AddOp(const std::string &type, const std::vector<std::string> &inputs,
const std::vector<std::string> &outputs,
const OpAttrs &attrs = OpAttrs());
void AddBackwardOps() override {}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we decided to net = Backward(net). return net composed by gradient.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

@@ -103,18 +79,10 @@ class Net {
class PlainNet : public Net {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since we have reached an agreement in treating net as a composed Op, seems we do not need a PlainNet anymore. We can have two types of Net, Net, DAGNet.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think net will have a common interface AddOp, so I add the net base interface with only AddOp

reyoung and others added 3 commits July 15, 2017 21:49
* OperatorBase should not store OpDesc, because not All op contains an
  OpDesc and not all ops create from OpDesc.
  * Networks do not contain OpDesc, and do not created by OpDesc
* Do not register Network to OpRegistry.
  * The network is directly created by user in Python. Not from
    registry.
* Correctly handle the `inputs` and `outputs` of a Network.
  * Add CompleteAddOp() methods
* Remove `AddOp(OpDesc&)`. All op are added by pointer.
* Rewrite unit test for truely tested what networks do.
* Remove `DemoOp` and `DemoOpTest` because it is useless and break the
  CI
@@ -1,135 +0,0 @@
/* Copyright (c) 2016 PaddlePaddle Authors. All Rights Reserve.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems that this file should not be removed?

Copy link
Collaborator

@reyoung reyoung left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, except @jacquesqiao should review this PR, too.

@jacquesqiao jacquesqiao merged commit 45ce164 into PaddlePaddle:develop Jul 16, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Design Network as a kind of Operator
3 participants